package com.btobtob.a.biz.user;

import com.btobtob.a.biz.user.commonweb.filter.CaseInsensitiveRequestParameterNameFilter;
import com.btobtob.a.biz.user.config.WebMvcConfigurerConfig;
import jakarta.servlet.FilterRegistration;
import jakarta.servlet.ServletContext;
import jakarta.servlet.ServletException;
import org.jetbrains.annotations.NotNull;
import org.springframework.web.servlet.support.AbstractAnnotationConfigDispatcherServletInitializer;

public class WebMvcInitializer extends AbstractAnnotationConfigDispatcherServletInitializer {

    @Override
    protected Class<?>[] getRootConfigClasses() {
        return new Class<?>[] { WebMvcConfigurerConfig.class };
    }

    @Override
    protected Class<?>[] getServletConfigClasses() {
        return new Class<?>[] { WebMvcConfigurerConfig.class };
    }

    @NotNull
    @Override
    protected String[] getServletMappings() {
        return new String[] { "/" };
    }

    @Override
    public void onStartup(@NotNull ServletContext servletContext) throws ServletException {
        super.onStartup(servletContext);
        FilterRegistration.Dynamic filter = servletContext.addFilter(CaseInsensitiveRequestParameterNameFilter.class.getSimpleName(), CaseInsensitiveRequestParameterNameFilter.class);
        filter.addMappingForUrlPatterns(null, true, "/*");
    }

}
